package com.zqxq.lottery.entity.o2o.sys;

import com.zqxq.common.utils.BigDecimalUtils;
import com.zqxq.common.utils.DispatcherUtils;
import com.zqxq.lottery.entity.po.sys.LotteryHnumPO;
import com.zqxq.lottery.entity.vo.sys.LotteryHnumVO;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description ：
 * @Author ： 解风
 * @Date ： 2018/03/14 16:12
 */
public class LotteryHnumO2O {

    public static LotteryHnumVO toVO(LotteryHnumPO po) {
        if (po == null) {
            return null;
        }
        LotteryHnumVO lotteryHnumVO = new LotteryHnumVO();
        lotteryHnumVO.setId(DispatcherUtils.parseString(po.getId()));
        lotteryHnumVO.setLotteryId(DispatcherUtils.parseString(po.getLottery_id()));
        lotteryHnumVO.setPeriod(po.getPeriod());
        lotteryHnumVO.setRedNum(po.getRed_num());
        lotteryHnumVO.setBlueNum(po.getBlue_num());
        lotteryHnumVO.setLotteryTime(DispatcherUtils.parseDateTimeStr(po.getLottery_time()));
        lotteryHnumVO.setCloseTime(DispatcherUtils.parseDateTimeStr(po.getClose_time()));
        lotteryHnumVO.setDeadlineTime(DispatcherUtils.parseDateTimeStr(po.getDeadline_time()));
        BigDecimal saleamountDecimal = BigDecimalUtils.getValue(po.getSale_amount(),2) ;
        String saleamount = saleamountDecimal == null ? null : saleamountDecimal.toPlainString();
        lotteryHnumVO.setSaleAmount(saleamount);
        BigDecimal totalmoneyDecimal = BigDecimalUtils.getValue(po.getTotal_money(),2) ;
        String totalmoney = totalmoneyDecimal == null ? null : totalmoneyDecimal.toPlainString();
        lotteryHnumVO.setTotalMoney(totalmoney);
        lotteryHnumVO.setWinNum(DispatcherUtils.parseString(po.getWin_num()));
        lotteryHnumVO.setApiResult(po.getApi_result());
        lotteryHnumVO.setStatus(DispatcherUtils.parseString(po.getStatus()));
        lotteryHnumVO.setCalcStatus(DispatcherUtils.parseString(po.getCalc_status()));
        lotteryHnumVO.setCreateTime(DispatcherUtils.parseDateTimeStr(po.getCreate_time()));
        lotteryHnumVO.setUpdateTime(DispatcherUtils.parseDateTimeStr(po.getUpdate_time()));
        return lotteryHnumVO;
    }

    public static LotteryHnumPO toPO(LotteryHnumVO vo) {
        if (vo == null) {
            return null;
        }
        LotteryHnumPO lotteryHnumPO = new LotteryHnumPO();
        lotteryHnumPO.setId(DispatcherUtils.parseLong(vo.getId()));
        lotteryHnumPO.setLottery_id(DispatcherUtils.parseLong(vo.getLotteryId()));
        lotteryHnumPO.setPeriod(vo.getPeriod());
        lotteryHnumPO.setRed_num(vo.getRedNum());
        lotteryHnumPO.setBlue_num(vo.getBlueNum());
        lotteryHnumPO.setLottery_time(DispatcherUtils.parseDateTime(vo.getLotteryTime()));
        lotteryHnumPO.setClose_time(DispatcherUtils.parseDateTime(vo.getCloseTime()));
        lotteryHnumPO.setDeadline_time(DispatcherUtils.parseDateTime(vo.getDeadlineTime()));
        lotteryHnumPO.setSale_amount(BigDecimalUtils.getBigDecimal(vo.getSaleAmount()));
        lotteryHnumPO.setTotal_money(BigDecimalUtils.getBigDecimal(vo.getTotalMoney()));
        lotteryHnumPO.setWin_num(DispatcherUtils.parseInteger(vo.getWinNum()));
        lotteryHnumPO.setApi_result(vo.getApiResult());
        lotteryHnumPO.setStatus(DispatcherUtils.parseInteger(vo.getStatus()));
        lotteryHnumPO.setCalc_status(DispatcherUtils.parseInteger(vo.getCalcStatus()));
        lotteryHnumPO.setCreate_time(DispatcherUtils.parseDateTime(vo.getCreateTime()));
        lotteryHnumPO.setUpdate_time(DispatcherUtils.parseDateTime(vo.getUpdateTime()));
        return lotteryHnumPO;
    }

    public static List<LotteryHnumVO> toVOList(List<LotteryHnumPO> list){
        List<LotteryHnumVO> result = new ArrayList<>();
        if(list != null && list.size() > 0){
            for(LotteryHnumPO po : list) {
                result.add(toVO(po));
            }
        }
        return result;
    }
}
